package com.honeyms.project.system.userdetail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.honeyms.framework.aspectj.lang.annotation.Log;
import com.honeyms.framework.aspectj.lang.enums.BusinessType;
import com.honeyms.project.system.userdetail.domain.UserDetail;
import com.honeyms.project.system.userdetail.service.IUserDetailService;
import com.honeyms.framework.web.controller.BaseController;
import com.honeyms.framework.web.domain.AjaxResult;
import com.honeyms.common.utils.poi.ExcelUtil;
import com.honeyms.framework.web.page.TableDataInfo;

/**
 * 用户详情Controller
 * 
 * @author honeyms
 * @date 2020-10-12
 */
@Controller
@RequestMapping("/system/userdetail")
public class UserDetailController extends BaseController
{
    private String prefix = "system/userdetail";

    @Autowired
    private IUserDetailService userDetailService;

    @RequiresPermissions("system:userdetail:view")
    @GetMapping()
    public String userdetail()
    {
        return prefix + "/userdetail";
    }

    /**
     * 查询用户详情列表
     */
    @RequiresPermissions("system:userdetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserDetail userDetail)
    {
        startPage();
        List<UserDetail> list = userDetailService.selectUserDetailList(userDetail);
        return getDataTable(list);
    }

    /**
     * 导出用户详情列表
     */
    @RequiresPermissions("system:userdetail:export")
    @Log(title = "用户详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserDetail userDetail)
    {
        List<UserDetail> list = userDetailService.selectUserDetailList(userDetail);
        ExcelUtil<UserDetail> util = new ExcelUtil<UserDetail>(UserDetail.class);
        return util.exportExcel(list, "userdetail");
    }

    /**
     * 新增用户详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户详情
     */
    @RequiresPermissions("system:userdetail:add")
    @Log(title = "用户详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserDetail userDetail)
    {
        return toAjax(userDetailService.insertUserDetail(userDetail));
    }

    /**
     * 修改用户详情
     */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        UserDetail userDetail = userDetailService.selectUserDetailById(userId);
        mmap.put("userDetail", userDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户详情
     */
    @RequiresPermissions("system:userdetail:edit")
    @Log(title = "用户详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserDetail userDetail)
    {
        return toAjax(userDetailService.updateUserDetail(userDetail));
    }

    /**
     * 删除用户详情
     */
    @RequiresPermissions("system:userdetail:remove")
    @Log(title = "用户详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userDetailService.deleteUserDetailByIds(ids));
    }
}
